home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Resources / System / BoingBag1 / Contributions / InstallerNG / GUI-API / example / igui_AskBool.c next >
C/C++ Source or Header  |  1999-10-31  |  4KB  |  137 lines

  1.  
  2. #include "includes.h"
  3. #include "installergui_data.h"
  4.  
  5. /********************************************************************
  6.  *
  7.  *  DESCRIPTION
  8.  *
  9.  *  build and show the ASKBOOL panel; the C= installer just
  10.  *  modifies the gadget texts, but this will not work with my
  11.  *  InstallerNG, since the ASKBOOL function can appear in a
  12.  *  SWING funtion and the buttons are used by the SWING function;
  13.  *  the best thing to solve this conflict was a ASKBOOL panel
  14.  *  with two MX buttons for "Yes" and "No"
  15.  *
  16.  *  IN:  application - pointer to the private application structure
  17.  *       localenv - the local environment of the related ASKBOOL
  18.  *                  function
  19.  *  OUT: 1 - if the user choses "Yes"
  20.  *       0 - if the user choses "No"
  21.  *
  22.  */
  23.  
  24. /********************************************************************
  25.  *
  26.  *  STATIC
  27.  *
  28.  */
  29.  
  30. static const struct Hook askbool_MXTwoHook = { { NULL, NULL }, (VOID *) guistuff_MXTwoFun, NULL, NULL };
  31. static const struct Hook askbool_SetValHook = { { NULL, NULL }, (VOID *) guistuff_SetValFun, NULL, NULL };
  32.  
  33. /********************************************************************
  34.  *
  35.  *  EXTERN
  36.  *
  37.  */
  38.  
  39. /********************************************************************
  40.  *
  41.  *  PUBLIC
  42.  *
  43.  */
  44.  
  45. /********************************************************************
  46.  *
  47.  *  CODE
  48.  *
  49.  */
  50.  
  51. long __asm igui_AskBool(register __a0 APTR application,
  52.                         register __a1 struct FunctionEnvironment *localenv)
  53. {
  54.   #ifdef DEBUG
  55.   DEBUG_MAKRO
  56.   #endif
  57.  
  58.   {
  59.     struct Application *app = (struct Application *) application;
  60.  
  61.     struct Node *yesnode, *nonode;
  62.  
  63.     // the default text values
  64.     char *yestext = app->app_Texts[YES],
  65.          *notext = app->app_Texts[NO];
  66.  
  67.     // by default, this returns 1
  68.     long retval = 1;
  69.  
  70.     // the different mui objects
  71.     APTR askbool, MX_yes, MX_no;
  72.  
  73.     // if there ware choices for ASKBOOL, then these choices are hold in an
  74.     // exec list and ln_Name does hold the values themselves
  75.     yesnode = sav_GetHead((struct List *) &(localenv->fe_Choices));
  76.     if (yesnode)
  77.     {
  78.       yestext = yesnode->ln_Name;
  79.       if (nonode = sav_GetSucc(yesnode)) { notext = nonode->ln_Name; }
  80.     }
  81.  
  82.     // no create and setup the mui object
  83.     // ---> note the tricky access to the retval via hooks ;)
  84.     askbool = GroupObject,
  85.                 Child, TextObject,
  86.                   MUIA_Text_Contents, localenv->fe_Prompt,
  87.                   MUIA_Text_SetMin, TRUE,
  88.                   MUIA_Text_PreParse, "\33c",
  89.                 End,
  90.                 Child, HVSpace,
  91.                 Child, HGroup,
  92.                   Child, HVSpace,
  93.                   Child, GroupObject,
  94.                     MUIA_Group_Columns, 2,
  95.                     Child, LLabel(yestext),
  96.                     Child, MX_yes = guistuff_InitRadio(TRUE, FALSE),
  97.                     Child, LLabel(notext),
  98.                     Child, MX_no = guistuff_InitRadio(FALSE, FALSE),
  99.                   End,
  100.                   Child, HVSpace,
  101.                 End,
  102.                 Child, HVSpace,
  103.               End;
  104.  
  105.     if (askbool)
  106.     {
  107.       DoMethod(MX_yes, MUIM_Notify, MUIA_Pressed, TRUE,
  108.                MUIV_Notify_Self, 4, MUIM_CallHook, &askbool_MXTwoHook, MX_yes, MX_no);
  109.       DoMethod(MX_no, MUIM_Notify, MUIA_Pressed, TRUE,
  110.                MUIV_Notify_Self, 4, MUIM_CallHook, &askbool_MXTwoHook, MX_no, MX_yes);
  111.  
  112.       DoMethod(MX_yes, MUIM_Notify, MUIA_Pressed, TRUE,
  113.                MUIV_Notify_Self, 4, MUIM_CallHook, &askbool_SetValHook, &retval, 1);
  114.       DoMethod(MX_no, MUIM_Notify, MUIA_Pressed, TRUE,
  115.                MUIV_Notify_Self, 4, MUIM_CallHook, &askbool_SetValHook, &retval, 0);
  116.  
  117.       // maybee BACK (if specified) or respect the swing mode
  118.       if (localenv->fe_Back)         { guistuff_SetBackButton(app, TRUE); }
  119.       else if (!app->app_SWING_Mode) { igui_NameCancel(app, (char *) app->app_GlobalEnv[GENV_ABORT_BUTTON]); }
  120.  
  121.       if (guistuff_NewContent(app, askbool))
  122.       {
  123.         // wait for the user
  124.         igui_WaitApp(app);
  125.       }
  126.     }
  127.     else { /* NO GUI OBJECT */ }
  128.  
  129.     // and done
  130.     if (localenv->fe_Back) { guistuff_SetBackButton(app, FALSE); }
  131.     
  132.     igui_EmptyPanel(app);
  133.     return(retval);
  134.   }
  135. }
  136.  
  137.